package cn.wen233.core.wrapper.query;

import cn.wen233.basic.exceptions.BaseException;
import cn.wen233.basic.model.Namespace;
import cn.wen233.core.mapper.NamespaceMapper;
import cn.wen233.core.utils.IocUtils;

import java.util.Optional;

/**
 * @author wenei
 * @date 2021-10-24 16:09
 */
public class NamespaceQuery {

    private static final NamespaceMapper namespaceMapper = IocUtils.getBean(NamespaceMapper.class);

    public static Namespace getByNamespaceId(String namespaceId) {
        return Optional.ofNullable(namespaceMapper.selectNamespaceByNamespaceId(namespaceId))
                .orElseThrow(() -> new BaseException("未找到namespaceId={%s}的命名空间", namespaceId));
    }
}
